package com.na.tools.ping.impl;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;

import com.na.tools.CommonTools;
import com.na.tools.ping.NetworkChecker.BatchNetworkChecker;

public class SocketNetworkChecker extends BatchNetworkChecker {

	@Override
	public long connect(String host) {
		Socket socket = null;
		try {
			long cost = System.currentTimeMillis();
			socket = new Socket();
			socket.connect(new InetSocketAddress(host, 80), 5000);
			return System.currentTimeMillis() - cost;
		} catch (IOException e) {
		} finally {
			CommonTools.closeIO(socket);
		}
		return Long.MAX_VALUE;
	}

}
